package com.etone.smartAudit.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etone.smartAudit.domain.ServerSource;
import com.etone.smartAudit.error.CustomParameterizedException;
import com.etone.smartAudit.mapper.ServerSourceMapper;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.serverSource.ServerSourceSimpleVO;
import com.etone.smartAudit.vo.serverSource.ServerSourceVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

/**
 * @author: sovy
 * @date: 2020/10/28
 * @description:
 */

@Service
public class ServerSourceService extends ServiceImpl<ServerSourceMapper, ServerSource> {

    /**
     * 服务器资源列表
     *
     * @param serverInfoId
     * @param page
     * @param pageSize
     * @return
     */
    public PagerVO<ServerSourceVO> list(Integer serverInfoId, int page, int pageSize) {
        Page<ServerSourceVO> serverSourceVOPage = PageHelper.startPage(page, pageSize).doSelectPage(() -> baseMapper.findList(serverInfoId));
        return PagerVO.of(serverSourceVOPage);

    }

    /**
     * 服务器资源详情
     *
     * @param id
     * @return
     */
    public ServerSourceVO detail(Integer id) {
        ServerSourceVO detail = baseMapper.findDetail(id);
        if (detail == null) {
            throw new CustomParameterizedException("服务器资源不存在");
        }
        return detail;
    }

    /**
     * 服务器资源基本信息列表
     *
     * @param page
     * @param pageSize
     * @return
     */
    public PagerVO<ServerSourceSimpleVO> listSimple(int page, int pageSize) {
        Page<ServerSourceSimpleVO> serverSourceSimpleVOPage = PageHelper.startPage(page, pageSize).doSelectPage(() -> baseMapper.findListSimple());
        return PagerVO.of(serverSourceSimpleVOPage);
    }
}
